function getSpInputText(cellvalue, rowObject, type, colNum) {
	var defaultVal;
	switch (type) {
	case 1:
		defaultVal = "";
		if (!cellvalue)
			cellvalue = defaultVal;
		return "<input  id='i_" + rowObject.id + "' type='text' value='" + cellvalue + "' onchange='saveSpRow(\"" + rowObject.id + "\")' style='width:75%'>";
		break;
	case 2:
		defaultVal = "0";
		if (!cellvalue)
			cellvalue = defaultVal;
		return "<input id='i" + colNum + "_" + rowObject.id + "' type='text' value='" + cellvalue + "' class='number'  onchange='computeSpAmount(\"" + rowObject.id + "\")' style='width:75%'>";
		break;
	case 3:
		defaultVal = "0";
		if (!cellvalue)
			cellvalue = defaultVal;
		return "<input id='i" + colNum + "_" + rowObject.id + "' type='text' value='" + cellvalue + "' class='number'  onchange='saveSpRow(\"" + rowObject.id + "\")' style='width:75%'>";
		break;

	}

}
function computeSpAmount(rowid) {

	var count = 0, amount = $("#amount");
	if (amount.length > 0) {
		var allRowsInGrid = $("#" + sparepart.gridId).jqGrid('getRowData');

		$(allRowsInGrid).each(function(index, item) {
			var id = item.id;
			count += ($("#i1_" + id).val() || 0) * ($("#i2_" + id).val() || 0);
		});
		$("#amount").val(count);
	}
	saveSpRow(rowid);
}

function saveSpRow(rowid) {
	var rowData = $("#" + sparepart.gridId).jqGrid('getRowData',rowid);
	var quantity = $("#i1_" + rowid).val() || rowData.quantity||0;
	var price = $("#i2_" + rowid).val() || 0;
	var repairInQy=$("#i4_" + rowid).val() || 0;
	var repairDiscardQy=$("#i3_" + rowid).val() || 0;
	var memo = $("#i_" + rowid).val() || "";
	$.post(sparepart.saveUrl, {
		"id" : rowid,
		"quantity" : quantity,
		"price" : price,
		"memo" : memo,
		"repairInQuantity":repairDiscardQy,
		"repairDiscardQuantity":repairInQy
	});

}